package com.ws.client;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.roc.util.Constance;

import net.sf.json.JSONObject;

/**
*@auhor   zbl
*@date    2017年4月11日 下午3:11:11
*@desc    说明 : 四要素验证
**/
public class FourElementValidateUtils {
	private static Logger logger=LogManager.getLogger(FourElementValidateUtils.class);
	
	// 测试
		// private static String address = "http://192.168.10.223:7003/webService/ProxyService";

		// 生产
	private static String address = "http://188.68.88.102:7005/webService/ProxyService";
		 
	/**获取四要素的数据 捷安
	 * @param accountName  结算账户名称
	 * @param userPid      身份证号
	 * @param accountNo    结算账户账号
	 * @param mobile       银行预留手机号码
	 * @return
	 * @throws RemoteException
	 * @throws ServiceException
	 * @throws MalformedURLException 
	 */
	public static boolean sendPayjnlsAuditOfJiean(String accountName,String userPid,String accountNo,String mobile	) throws Exception {
		boolean result = false;
		Map<String,String> paramMap = new HashMap<String, String>();
		paramMap.put("TRADE_CODE", "ZX0005");
		paramMap.put("TX_BLESS_TYPE", accountName);
		paramMap.put("TX_USER_ID", userPid);
		paramMap.put("TX_CARD_NUM", accountNo);
		paramMap.put("TX_MOBILE_NO", mobile);
		paramMap.put("TX_ORDER_CODE", "2");
		paramMap.put("TRADE_KEY", Constance.isTid());//随机
		paramMap.put("TRN_TX_DATE", Constance.currTime());//日期
		paramMap.put("TRN_TX_TIME",  Constance.currTime1());//时间
		try {
			paramMap = sendWebService(paramMap);
			logger.info("捷安四要素验证 调用接口参数："+paramMap.toString()+"返回结果：『" + paramMap + "』。");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new Exception(e);
		}
		if ("00".equals(paramMap.get("MSG_CODE"))) {
			result = true;
		}
		return result;
	}
	
	/**
	 * 调用接口
	 * 
	 * @param param
	 * @return
	 * @throws Exception
	 */
	private static Map<String, String> sendWebService(Map<String, String> param)
			throws Exception {
		ProxyServiceLocator ps = new ProxyServiceLocator();
		String result = "";
		try {
			result = ps.getProxyPort(new java.net.URL(address)).service(
					JSONObject.fromObject(param).toString());
			param = (HashMap<String, String>) JSONObject.toBean(
					JSONObject.fromObject(result), HashMap.class);
		} catch (Exception e) {
			logger.error("调用四要素出错了",e);
			throw new Exception(e);
		}
		return param;
	}
	public static void main(String[] args) throws Exception {
		
		String accountName="姓名";
		String userPid="411528199411063332";
		String accountNo="6227002432340378623";
		String mobile="13700860967";	
	 boolean result=FourElementValidateUtils.sendPayjnlsAuditOfJiean(accountName, userPid, accountNo, mobile);
	 System.out.println(result);
	
	}
}
